unit UGetExeVersion;

interface
function getVersion : string;

implementation

uses Windows, SysUtils, Forms;

function getVersion : string;
var
  dump :DWORD;
  buffer :PChar;
  size, Temp :integer;
  CalcLangCharSet :string;
  VersionPointer, TransBuffer :PChar;
begin

  size := GetFileVersionInfoSize(PChar(Application.ExeName), dump);
  buffer := StrAlloc(size+1);
  try
    GetFileVersionInfo(PChar(Application.ExeName), 0, size, buffer);
    VerQueryValue(buffer, '\VarFileInfo\Translation', pointer(TransBuffer),dump);
    if dump >= 4 then begin
      temp := 0;
      StrLCopy(@temp, TransBuffer, 2);
      CalcLangCharSet := IntToHex(temp, 4);
      StrLCopy(@temp, TransBuffer+2, 2);
      CalcLangCharSet := CalcLangCharSet+IntToHex(temp, 4);
    end;

    VerQueryValue(buffer, pchar('\StringFileInfo\'+CalcLangCharSet+'\'+'FileVersion'), pointer(VersionPointer), dump);

    if (dump > 1) then begin
      SetLength(Result, dump-1);
      StrLCopy(Pchar(Result), VersionPointer, dump-1);
    end else Result := '0.0.0.0';
  finally
    StrDispose(Buffer);
  end;
end;


end.
 